package dynamicPlan;

//最长公共前缀
public class longestCommonPrefix {
    public String findLongestCommonPrefix(String[]strings){
        String temp = strings[0];
        for (int i=1;i<strings.length;i++){
            while(!strings[i].startsWith(temp)){
                System.out.println(temp);
                temp=temp.substring(0,temp.length()-1);
                if(temp.length()==0){
                    return "";
                }

            }
        }

        return temp;
    }

    public static void main(String[] args) {
        String[] strings = {"c","acc","ccc"};
        longestCommonPrefix longestCommonPrefix = new longestCommonPrefix();
        System.out.println(longestCommonPrefix.findLongestCommonPrefix(strings));

    }
}